cars = ['audi','bmw','subaru','toyota']

for car in cars:
	if car == 'bmw':
		print(car+"----if")
		print(car == 'bmw')
	else:
		print(car+"----else")
		print(car == 'bmw')


print("-------")
print("help" == "HELP")	#区分大小写
print("-------")



#检查多个条件 and or

age_1 = 24
age_2 = 33
print(age_1>=21 and age_2<=24)
print(age_1>=21 or age_2<=24)

#检查特定值是否包含在列表中  in
requested_toppings = ['mushrooms','onions','pineapple']
a_1 = 'mushrooms' in requested_toppings
a_2 = 'mushroom' in requested_toppings
print(a_1)
print(a_2)

#检查特定值是否不包含在列表中  not in
topping = "pine"
if topping not in requested_toppings:
	print(topping.title()+", you can post a response if you wish.")

car = 'subaru'
print("Is car == 'subaru'? I predict True.") 
print(car == 'subaru')
print("\nIs car == 'audi'? I predict False.") 
print(car == 'audi')


# 判断语句 if elif  else
age = 1
if age >= 18:
	print('you are old enough to vote!')
elif age < 4:
	print("you are a kid!")
else:
	print('Sorry ,you are too young to vote!')

print("--------------")

requested_toppings = []
if requested_toppings:
	for requested_topping in requested_toppings:
		print("Adding "+ requested_topping +".")
	print("\nFinished making your pizza?")
else:
	print("\nAre you sure you want a plain pizza?")



#字典
alien_0 = {'color':'green','points':'5'}

print(alien_0['color'])
print(alien_0['points'])


print(alien_0)
alien_0['x_position'] = 0
alien_0['y_position'] = 25
print(alien_0)


alien_1 = {'x_position': 0, 'y_position': 25, 'speed': 'medium'} 
print("Original x-position: " + str(alien_1['x_position']))

# 向右移动外星人
# 据外星人当前速度决定将其移动多远 
if alien_1['speed'] == 'slow':
    x_increment = 1
elif alien_1['speed'] == 'medium':
    x_increment = 2 
else:
    # 这个外星人的速度一定很快 
    x_increment = 3

# 新位置等于老位置加上增量
alien_1['x_position'] = alien_1['x_position'] + x_increment
print("New x-position: " + str(alien_1['x_position']))

#删除键值对
print(alien_0)
del alien_0['x_position']
del alien_0['y_position']
print(alien_0)

#遍历字典
user_0 = {
    'username': 'efermi',
    'first': 'enrico',
    'last': 'fermi',
}
for key, value in user_0.items():
    print("\nKey: " + key)
    print("Value: " + value)

favorite_languages = { 
    'jen': 'python',
    'sarah': 'c',
    'edward': 'ruby',
    'phil': 'python', 
}
for name, language in favorite_languages.items():
    print(name.title() + "'s favorite language is " +
        language.title() + ".")

# 1 2遍历key   3遍历values
# keys方法实际上返回了一个列表，包含字典中所有的键

for name in favorite_languages.keys(): 
    print(name.title())

for name in favorite_languages: 
    print(name.title())

for name in favorite_languages.values(): 
    print(name.title())

print("---------")
#调用set()剔除重复元素
for name in set(favorite_languages.values()): 
    print(name.title())


#嵌套
alien_0 = {'color': 'green', 'points': 5} 
alien_1 = {'color': 'yellow', 'points': 10} 
alien_2 = {'color': 'red', 'points': 15}

aliens = [alien_0, alien_1, alien_2]

for alien in aliens: 
    print(alien)


# 创建一个用于存储外星人的空列表
aliens = []
# 创建30个绿色的外星人
for alien_number in range(30):
    new_alien = {'color': 'green', 'points': 5, 'speed': 'slow'}
    aliens.append(new_alien)

for alien in aliens[0:3]:
    if alien['color'] == 'green':
        alien['color'] = 'yellow' 
        alien['speed'] = 'medium' 
        alien['points'] = 10
    elif alien['color'] == 'yellow': 
        alien['color'] = 'red' 
        alien['speed'] = 'fast' 
        alien['points'] = 15
# 显示前五个外星人
for alien in aliens[:5]:
    print(alien)
print("...")
# 显示创建了多少个外星人
print("Total number of aliens: " + str(len(aliens)))



#在字典中存储列表
favorite_languages = {
    'jen': ['python', 'ruby'],
    'sarah': ['c'],
    'edward': ['ruby', 'go'],
    'phil': ['python', 'haskell']
}
for name, languages in favorite_languages.items(): 
    print("\n" + name.title() + "'s favorite languages are:")
    for language in languages: 
        print("\t" + language.title())

users = { 
    'aeinstein': {
        'first': 'albert', 
        'last': 'einstein', 
        'location': 'princeton', 
    },
    'mcurie': {
        'first': 'marie', 
        'last': 'curie', 
        'location': 'paris', 
    },
}

for username, user_info in users.items():
    print("\nUsername: " + username)
    full_name = user_info['first'] + " " + user_info['last'] 
    location = user_info['location']
    
    print("\tFull name: " + full_name.title()) 
    print("\tLocation: " + location.title())

